import 'event_bus.dart';

typedef EventResult<E> = void Function(E arg);

class EventBusUtils {
  //私有构造函数
  EventBusUtils._internal();

  //保存单例
  static final EventBusUtils _singleton = EventBusUtils._internal();

  //工厂构造函数
  factory EventBusUtils() => _singleton;

  //激励视频
  void jlspSucceedOn(EventCallback<String> f) {
    bus.on("loginSucceed", (arg) {
      f(arg["message"]);
    });
  }

  void jlspSucceedEmit({String message = ""}) {
    bus.emit("loginSucceed", {
      "message": message,
    });
  }

  void jlspSucceedOff() {
    bus.off("loginSucceed");
  }

  //插屏
  void cpSucceedOn(EventCallback<String> f) {
    bus.on("cpSucceedOn", (arg) {
      f(arg["message"]);
    });
  }

  void cpSucceedEmit({String message = ""}) {
    bus.emit("cpSucceedOn", {
      "message": message,
    });
  }

  void cpSucceedOff() {
    bus.off("cpSucceedOn");
  }

  //两个插屏
  void cpSucceedOnTow2(EventCallback<String> f) {
    bus.on("cpSucceedOnTow2", (arg) {
      f(arg["message"]);
    });
  }

  void cpSucceedEmitTow2({String message = ""}) {
    bus.emit("cpSucceedOnTow2", {
      "message": message,
    });
  }

  void cpSucceedOffTow2() {
    bus.off("cpSucceedOnTow2");
  }

  //开屏监听
  void kpSucceedOn(EventCallback<String> f) {
    bus.on("kpSucceed", (arg) {
      f(arg["message"]);
    });
  }

  //开屏通知
  void kpSucceedEmit({String message = ""}) {
    bus.emit("kpSucceed", {
      "message": message,
    });
  }

  void kpSucceedOff() {
    bus.off("kpSucceed");
  }

  //微信登录通知
  void wxSucceedOn(EventCallback<String> f) {
    bus.on("wxSucceed", (arg) {
      f(arg["message"]);
    });
  }

  //微信登录通知
  void wxSucceedEmit({String message = ""}) {
    bus.emit("wxSucceed", {
      "message": message,
    });
  }

  void wxSucceedOff() {
    bus.off("wxSucceed");
  }
}

var eventBusUtils = EventBusUtils();
